Skip to content

ENH: Add equivalence test for float in to_numeric() GH43693 #43710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

jbencina
Copy link
Contributor

This PR prevents issues where float64 arrays would be downcast to float32 arrays even if the values were out of range for float32. An equivalence check is performed to ensure all values are equal to 7 significant digits. If this fails, the original float64 is retained. This behavior is consistent with int where downcasting is not performed if the integer is out of bounds.

Pre Change:

>>> pd.to_numeric(pd.Series([608202549.0]), downcast='float')
0    608202560.0

Post Change:

>>> pd.to_numeric(pd.Series([608202549.0]), downcast='float')
0    608202549.0

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Oct 24, 2021
@jbencina jbencina force-pushed the jbencina-43693 branch 2 times, most recently from b0dfbaa to 3d57ec1 Compare December 12, 2021 16:59
@jreback jreback added Numeric Operations Arithmetic, Comparison, and Logical operations and removed Stale labels Jan 16, 2022
@jreback
Copy link
Contributor

jreback commented Jan 16, 2022

@jbencina can you move the note, this looks good

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls move the note and merge master

@jbencina
Copy link
Contributor Author

@jreback Moved the change to V1.5.0. Not sure why this PR has trouble with the CI checks, but I don't think it's related to my code (eg. Azure timing out)

@jreback jreback added this to the 1.5 milestone Jan 17, 2022
@jreback jreback merged commit 4546015 into pandas-dev:main Jan 17, 2022
@jreback
Copy link
Contributor

jreback commented Jan 17, 2022

thanks @jbencina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_numeric incorrectly converting values >= 16,777,217 with downcast='float'
2 participants